﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using OreSystem.BLL;
using System.IO;
namespace MainFrom {
    public partial class Report_HuiZong : Form {
        public Report_HuiZong()
        {
            InitializeComponent();
        }

       

        private void button1_Click(object sender, EventArgs e) {
            reportViewer1.Clear();
            string rdlcPaht = AppDomain.CurrentDomain.BaseDirectory+"rdlc"+"\\"+"Report1.rdlc";
            ReportViewLoaddata(this.reportViewer1,dateTimePicker1.Value,dateTimePicker2.Value,rdlcPaht);
        }
        private void button2_Click(object sender, EventArgs e) {
            this.reportViewer1.Clear();
            string rdlcPaht = AppDomain.CurrentDomain.BaseDirectory + "rdlc" + "\\" + "Report2.rdlc";
            ReportViewLoaddata(this.reportViewer1, dateTimePicker1.Value, dateTimePicker2.Value, rdlcPaht);
        }
        public void ReportViewLoaddata(ReportViewer reportViewer, DateTime date1,DateTime date2,string Localrdlc) {
            ReportDataSource rds = new ReportDataSource();
            reportViewer.AutoSize = true;
            reportViewer.ZoomMode = ZoomMode.PageWidth;
            //this.reportViewer1.LocalReport.ReportEmbeddedResource = "MainFrom.Report1.rdlc";
            this.reportViewer1.LocalReport.ReportPath = Localrdlc;
            rds.Name = "DataSet1";
            DateTime startDate = new DateTime(date1.Year, date1.Month, date1.Day);
            DateTime endDate = new DateTime(date2.Year, date2.Month, date2.Day).AddDays(1).AddSeconds(-1);
            ReportParameter p1 = new ReportParameter("StartDate",startDate.ToShortDateString());
            ReportParameter p2 = new ReportParameter("EndDate",endDate.ToShortDateString());
            //reportViewer.LocalReport.SetParameters(new ReportParameter[]{});
            reportViewer.LocalReport.SetParameters(new ReportParameter[] { p1,p2 });
            rds.Value = new ItemTableBLL().GetList(startDate, endDate);
            reportViewer.LocalReport.DataSources.Clear();
            reportViewer.LocalReport.DataSources.Add(rds);            
            //this.reportViewer1.Refresh();
            reportViewer.RefreshReport();
        }

        private void Report_HuiZong_Resize(object sender, EventArgs e)
        {
            reportViewer1.Width = this.Width - 20;
            reportViewer1.Height = this.Height - 100;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.reportViewer1.Clear();
            string rdlcPaht = AppDomain.CurrentDomain.BaseDirectory + "rdlc" + "\\" + "Report3.rdlc";
            ReportViewLoaddata(this.reportViewer1, dateTimePicker1.Value, dateTimePicker2.Value, rdlcPaht);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.reportViewer1.Clear();
            string rdlcPaht = AppDomain.CurrentDomain.BaseDirectory + "rdlc" + "\\" + "Report4.rdlc";
            ReportViewLoaddata(this.reportViewer1, dateTimePicker1.Value, dateTimePicker2.Value, rdlcPaht);
        }

        private void button5_Click(object sender, EventArgs e)
        {
           
            reportViewer1.ZoomMode = ZoomMode.PageWidth;
            //this.reportViewer1.LocalReport.ReportEmbeddedResource = "MainFrom.Report1.rdlc";
            string rdlcPaht = AppDomain.CurrentDomain.BaseDirectory + "rdlc" + "\\" + "Report5.rdlc";
            this.reportViewer1.LocalReport.ReportPath = rdlcPaht;
            DateTime date1 = dateTimePicker1.Value;
            DateTime date2 = dateTimePicker2.Value;
            DateTime startDate = new DateTime(date1.Year, date1.Month, date1.Day);
            DateTime endDate = new DateTime(date2.Year, date2.Month, date2.Day).AddDays(1).AddSeconds(-1);
            ReportParameter p1 = new ReportParameter("StartDate", startDate.ToShortDateString());
            ReportParameter p2 = new ReportParameter("EndDate", endDate.ToShortDateString());
            //reportViewer.LocalReport.SetParameters(new ReportParameter[]{});
            reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2 });
            ReportDataSource rds = new ReportDataSource();
            rds.Name = "DataSet1";
            rds.Value = new ItemTableBLL().GetList(startDate, endDate, (int)cmbCarNo.SelectedValue);
            reportViewer1.LocalReport.DataSources.Clear();
            reportViewer1.LocalReport.DataSources.Add(rds);
            //this.reportViewer1.Refresh();
            reportViewer1.RefreshReport();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.reportViewer1.Clear();
            string rdlcPaht =  comboBox1.SelectedValue.ToString();
            ReportViewLoaddata(this.reportViewer1, dateTimePicker1.Value, dateTimePicker2.Value, rdlcPaht);
        }

        private void Report_HuiZong_Load(object sender, EventArgs e)
        {
            cmbCarNo.ValueMember = "ID";
            cmbCarNo.DisplayMember = "CarNo";
            cmbCarNo.DataSource = new ItemTableBLL().GetAllCar();
            string rlcPath = AppDomain.CurrentDomain.BaseDirectory + "rdlc";
            List<object> rlcData = new List<object>();
            string[] files = Directory.GetFiles(rlcPath);
            foreach (var item in files)
            {
                FileInfo file = new FileInfo(item);
                rlcData.Add(new { Text = file.Name.Substring(0, file.Name.IndexOf('.')), Value = file.FullName });
            }
            comboBox1.ValueMember = "Value";
            comboBox1.DisplayMember = "Text";
            comboBox1.DataSource = rlcData;
        }

      

       
    }
}
